package response

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type Response struct {
	Code    int         `json:"code"`    // 自定义错误码
	Data    interface{} `json:"data"`    // 数据
	Message string      `json:"message"` // 信息
}

func Success(c *gin.Context, data interface{}) {
	c.JSON(http.StatusOK, Response{
		0,
		data,
		"ok",
	})
}

func XSuccess(c *gin.Context) {
	c.JSON(http.StatusOK, Response{
		0,
		nil,
		"ok",
	})
}

func Fail(c *gin.Context, Code int, Msg string) {
	c.JSON(http.StatusOK, Response{
		Code,
		nil,
		Msg,
	})
}

func XFail(c *gin.Context, Msg string) {
	c.JSON(http.StatusOK, Response{
		500,
		nil,
		Msg,
	})
}
